package cn.sc.summer.summerboot.config;

import cn.sc.summer.summerboot.listener.RedisKeyExpirationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

import javax.annotation.Resource;

/**
 * 类名：key过期监听配置类
 *
 * @author a-xin
 * @date 2023/8/29 16:02
 */
@Configuration
public class RedisKeyExpirationConfig {

    @Resource
    RedisConnectionFactory factory;

    @Bean
    RedisMessageListenerContainer container() {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(factory);
        return container;
    }

    @Bean
    RedisKeyExpirationListener keyExpirationListener(RedisMessageListenerContainer listenerContainer) {
        return new RedisKeyExpirationListener(listenerContainer);
    }

}
